#include "Tree.h"

Slide* Tree::bitmapsA = NULL;
Slide* Tree::bitmapsB = NULL;
Slide* Tree::bitmapsC = NULL;

Tree::Tree(char type, Point<float> pos) : MovingSprite() {
	loadBitmap();

	ani->go();
	if(type == 1)
		ani->setSlide(bitmapsA, 50);
	else if(type == 2)
		ani->setSlide(bitmapsB, 75);
	else if(type == 3)
		ani->setSlide(bitmapsC, 100);

	this->start(pos);
}

void Tree::loadBitmap() {
	if(bitmapsA != NULL)
		return;

	bitmapsA = new Slide();
	bitmapsB = new Slide();
	bitmapsC = new Slide();
	
	bitmapsA->image = al_load_bitmap("rsc/Objects/Tree/treeA.tga");
	bitmapsA->slideWidth = 128;
	bitmapsA->slideHeight = 128;
	bitmapsA->numSlides = 8;
	bitmapsB->image = al_load_bitmap("rsc/Objects/Tree/treeB.tga");
	bitmapsB->slideWidth = 128;
	bitmapsB->slideHeight = 128;
	bitmapsB->numSlides = 8;
	bitmapsC->image = al_load_bitmap("rsc/Objects/Tree/treeC.tga");
	bitmapsC->slideWidth = 128;
	bitmapsC->slideHeight = 128;
	bitmapsC->numSlides = 8;
}

void Tree::update() {}

void Tree::draw(Point<float> camPos) {
	al_draw_bitmap(ani->getImage(), pos.x - camPos.x - 16, pos.y - camPos.y - 48, 0);
}

void Tree::deleteImages() {
	if(bitmapsA == NULL)
		return;

	al_destroy_bitmap(bitmapsA->image);
	al_destroy_bitmap(bitmapsB->image);
	al_destroy_bitmap(bitmapsC->image);

	delete bitmapsA;
	delete bitmapsB;
	delete bitmapsC;
	bitmapsA = NULL;
}